<?php


namespace Plugin\Supportforwhatsapp;

class Bootstrap
{
    public function boot()
    {
        //右下角的客服
        add_hook_blade('footer.after', function ($callback, $output, $data) {
            $setting = plugin_setting('customer_support');
            $supportinfo = [];
            $supportinfo['presales_whatsapp_number'] =  isset($setting['presales_whatsapp_number']) && $setting['presales_whatsapp_number'] ? $setting['presales_whatsapp_number'] : '';
            $supportinfo['aftermarket_whatsapp_number'] =  isset($setting['aftermarket_whatsapp_number']) && $setting['aftermarket_whatsapp_number'] ? $setting['aftermarket_whatsapp_number'] : '';

            $supportinfo['presales_whatsapp_number_lable'] =  isset($setting['presales_whatsapp_number_lable']) && $setting['presales_whatsapp_number_lable'] ? $setting['presales_whatsapp_number_lable'][locale()] : '';
            $supportinfo['aftermarket_whatsapp_number_lable'] =  isset($setting['aftermarket_whatsapp_number_lable']) && $setting['aftermarket_whatsapp_number_lable'] ? $setting['aftermarket_whatsapp_number_lable'][locale()] : '';

            $view = view('Supportforwhatsapp::shop.support', $supportinfo)->render();
            return $output . $view;
        });

        //订单支付后订单详细页显示订单跟踪whatsapp 
        add_hook_blade('account.order.info.order_details.top', function ($callback, $output, $data) {
            $setting = plugin_setting('customer_support');
            $trackorder = [];
            $trackorder['Track_Order_whatsapp_number'] =  isset($setting['Track_Order_whatsapp_number']) && $setting['Track_Order_whatsapp_number'] ? $setting['Track_Order_whatsapp_number'] : '';

            $view = view('Supportforwhatsapp::shop.track_order', $trackorder)->render();
            return $output . $view;
        });

        //页面顶部显示订单跟踪whatsapp 
        add_hook_blade('header.top.right', function ($callback, $output, $data) {
            $setting = plugin_setting('customer_support');
            $trackorder = [];
            $trackorder['Track_Order_whatsapp_number'] =  isset($setting['Track_Order_whatsapp_number']) && $setting['Track_Order_whatsapp_number'] ? $setting['Track_Order_whatsapp_number'] : '';

            $view = view('Supportforwhatsapp::shop.header_track_order', $trackorder)->render();
            return $output . $view;
        });
    }
}
